<?php
namespace Home\Controller;
use Think\Controller;
/**
 * 公共控制器
 */
class HomeController extends Controller {
	protected $uid;
	protected $auth_code;
	protected $timeout;
	/**
	 * 构造函数
	 */
	public function _initialize() {
		$session_user = session('user');
		if (is_null($session_user)) {
			$this->redirect('User/login');
		}
		$this->_checkTimeout();
		$this->uid = $session_user['uid'];
		$this->auth_code = $session_user['auth_code'];
		$this->timeout = $session_user['timeout'];
		
		session('pwd_timeout', NOW_TIME);
	}
	/**
	 * 空操作
	 */
	public function _empty() {
		$this->redirect('User/login');
	}
	/**
	 * 超时检查
	 */
	protected function _checkTimeout() {
		$pwd_timeout = session('pwd_timeout');
		$session_user = session('user');
		if (NOW_TIME > ($pwd_timeout + $session_user['timeout'] * 60)) {
			session('tmp_user', $session_user['email']);
			session('user', null);
			$this->redirect('User/login');
		}
	}
	/**
	 * 更新密码数量
	 */
	protected function _updatePasswordNum($category_id, $model_category, $model_password) {
		$map = array();
		$map['uid'] = $this->uid;
		$map['category_id'] = $category_id;
		$map['status'] = 1;
		
		$password_num = $model_password->where($map)->count();
		
		$map_category = array();
		$map_category['id'] = $category_id;
		$map_category['uid'] = $this->uid;
		
		$data_category = array();
		$data_category['password_num'] = $password_num;
		$model_category->where($map_category)->save($data_category);
	}
}